package de.ghost23.common.process {
	import flash.events.Event;

	/**
	* This event is thrown, when a Process or ICommand has failed or successfully finished.
	* @author Sven Busse
	* @version 1.0
	*/
	public class ProcessEvent extends Event {
		
		/**
		 * ID for the event, that a Process or ICommand has successfully finished.
		 */
		public static const COMPLETED:String = "onProcessCompleted";
		
		/**
		 * ID for the event, that a Process or ICommand has failed.
		 */
		public static const FAILED:String = "onProcessFailed";

		/**
		 * ID for the event, that the process is advancing. In the end, this is triggered by the individual ICommands.
		 */
		public static const PROGRESS:String = "onProgress";

		/**
		 * ID for the event, that an ICommand has finished.
		 */
		public static const COMMAND:String = "onCommand";
		
		/**
		* Optional. Only for DialogCommands and DialogProcesses.
		* The resulting code, that has been set by the finished DialogCommand.
		*/
		public var resultCode:String;
		
		/**
		 * Optional. Only for Process or BranchProcess. Holds a reference to the ICommand,
		 * that completed previously in the case of Process.COMMAND or caused the failure in the case of Process.FAILED.
		 */
		public var command:Class;

		/**
		 * Optional. Only used in conjunction with PROGRESS Event type. A number between 0 and 1, indicating
		 * the progress of the Command or Process, that fired this event. Default is 1.
		 */
		public var progress:Number = 1;
		
		/**
		* Creates a new ProcessEvent.
		* @param	type The type. Should be either ProcessEvent.COMPLETED or ProcessEvent.FAILED
		* @param	resultCode Optional. Only for TreeProcesses.
		* The resulting code, that has been set by the finished ICommand.
		* @param	 command Optional. Only for Process or BranchProcess. A class reference(!) to the ICommand,
		 * that completed previously in the case of Process.COMMAND or caused the failure in the case of Process.FAILED.
		*/
		public function ProcessEvent(type:String, resultCode:String=null, command:Class=null, progress:Number=1) {
			super(type);
			
			if (resultCode != null) this.resultCode = resultCode;
			if ( command != null) this.command =  command;
			this.progress = progress;
		}
		
		override public function clone():Event {
			return new ProcessEvent(type, resultCode, command);
		}
		
		override public function toString():String{
			return "de.ghost23.common.process.ProcessEvent";
		}
	}
}